define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'auser/index' + location.search,
                    add_url: 'auser/add',
                    edit_url: 'auser/edit',
                    del_url: 'auser/del',
                    multi_url: 'auser/multi',
                    import_url: 'auser/import',
                    table: 'auser',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons:[
                                {
                                    name: 'detail',
                                    text: '审核通过',
                                    title: '审核通过',
                                    classname: 'btn btn-xs btn-danger btn-ajax',
                                    icon: 'fa fa-address-book-o',
                                    url: 'auser/passed',
                                    confirm:'确认审核通过此用户?',
                                    success: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        $(".btn-refresh").trigger('click')
                                        return false;
                                    },
                                    visible: function (row) {
                                        if (row.ischeck == 0){
                                            //返回true时按钮显示,返回false隐藏
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    }
                                },
                                {
                                    name: 'detail',
                                    text: '已通过',
                                    title: '已通过',
                                    classname: 'btn btn-xs btn-success',
                                    icon: 'fa fa-address-book-o',
                                    visible: function (row) {
                                        if (row.ischeck == 1){
                                            //返回true时按钮显示,返回false隐藏
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.operate},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'company', title: __('Company'), operate: 'LIKE'},
                        {field: 'category.name', title: '部门名称', operate: 'LIKE'},
                        {field: 'jobsname', title: '职位', operate: 'LIKE'},
                        {field: 'gender', title: __('Gender'), searchList: {"0":__('Gender 0'),"1":__('Gender 1')}, formatter: Table.api.formatter.normal},
                        {field: 'birthday', title: __('Birthday'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,  formatter: Table.api.formatter.datetime, datetimeFormat:"YYYY-MM-DD"},
                        // {field: 'cate_id', title: __('Cate_id')},
                        // {field: 'jobs_id', title: __('Jobs_id')},
                        // {field: 'role', title: __('Role'), searchList: {"0":__('Role 0'),"1":__('Role 1')}, formatter: Table.api.formatter.normal},
                        // {field: 'pid', title: __('Pid')},
                        // {field: 'age', title: __('Age')},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'avatar', title: __('Avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'ctime', title: __('Ctime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime, datetimeFormat:"YYYY-MM-DD"},
                        {field: 'ji_fen', title: __('Ji_fen'), operate: 'LIKE'},
                        {field: 'all_fen', title: __('All_fen')},
                        {field: 'xue_fen', title: __('Xue_fen'), operate: 'LIKE'},
                        {field: 'longs', title: __('Longs')},
                        {field: 'jobyear', title: __('Jobyear'), operate:'RANGE',addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime, datetimeFormat:"YYYY-MM-DD"},
                        {field: 'jobtime', title: __('Jobtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime, datetimeFormat:"YYYY-MM-DD"},
                        {field: 'openid', title: __('Openid'), operate: 'LIKE'},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});